{include file='header'/}
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-row hui-form-search">
            <form class="layui-form layui-col-md12" action="javascript:;" id="form_admin_search">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="title" id="title" placeholder="请输入标题" autocomplete="off"
                               class="layui-input">
                    </div>
                    <div class="layui-inline" style="width:120px;">
                        <input type="text" name="id" id="id" placeholder="请输入文章ID" autocomplete="off"
                               class="layui-input">
                    </div>
                    <div class="layui-inline" style="width:160px;">
                        <select name="cate_id" id="cate_id">
                            <option value="">==文章分类==</option>
                            {foreach name="cates" key="k" id="v"}
                            <option value="{$v.id}"
                            <?php if($v['model_id']!=$model_id){echo "disabled";} ?>
                            >
                            {$v.name|raw}
                            </option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="layui-inline" style="width:120px;">
                        <select name="flag" id="attributes">
                            <option value="">==文章属性==</option>
                            {foreach name="flags" id="vo" key="k"}
                            <option value="{$k}">{$vo}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="layui-inline" style="width:120px;">
                        <select name="status" id="status">
                            <option value="">==文章状态==</option>
                            <option value="1">已发布</option>
                            <option value="0">未发布</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-md" data-type="reload" lay-submit="" lay-filter="search">
                            <i class="layui-icon layui-icon-search"></i>搜索
                        </button>
                        <button class="layui-btn layui-btn-danger layui-btn-md reset" type="reset">
                            <i class="layui-icon">&#xe63f;</i>清空
                        </button>
                    </div>

                </div>
            </form>
        </div>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="admin_table" lay-filter="admin_table"></table>
    </div>
</div>
<script type="text/html" id="add_toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md"
            data-open-full="{:url('content/add',['model_id'=>$model_id])}"
            data-title="添加文章">
        <i class="layui-icon layui-icon-add-1"></i>
        添加文章
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-md"
            data-open-full="{:url('content/recycle',['model_id'=>$model_id])}"
            data-title="回收站管理" data-reload="2">
        <i class="layui-icon layui-icon-fonts-strong"></i>
        回收站管理
    </button>
</script>

<script type="text/html" id="titleTpl">
    <a href="javascript:;" target="_blank">
        <span class="title_color" style="color:{{d.color}}">
            {{d.title}}
        </span>
    </a>
</script>
<script type="text/html" id="flagTpl">
    {{-d.flag_name}}
</script>
<script type="text/html" id="thumbTpl">
    {{#  if(d.thumb){ }}
    <img id="thumb_{{d.id}}" src="{{d.thumb}}" alt="" width="35" height="35"
         onmouseover="hui_img_preview('thumb_{{d.id}}','{{d.thumb}}')"
         onmouseout="layer.closeAll();">
    {{#  } }}
</script>
<script type="text/html" id="barDemo">
    <button class="pear-btn pear-btn-primary pear-btn-xs" title="编辑"
            data-open-full="{:url('content/edit')}?id={{d.id}}&model_id={$model_id}"
            data-title="编辑">
        <i class="layui-icon layui-icon-edit"></i>
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-xs" title="删除"
            data-delete="{:url('content/delete')}?id={{d.id}}"
            data-title="您确定要删除吗？" data-table-id="testReload">
        <i class="layui-icon layui-icon-delete"></i>
    </button>
</script>
{include file='footer'/}
<script>
  layui.use(['table', 'jquery'], function () {
    var $ = layui.jquery;
    var table = layui.table;
    table.render({
      elem: '#admin_table'
      , toolbar: '#add_toolbar'
      , defaultToolbar: [{
        layEvent: 'refresh',
        icon: 'layui-icon-refresh',
        title: '刷新'
      }, 'filter']
      , method: 'get'
      , where: {model_id:'{$model_id}'}
      , url: "{:url('content/index')}"
      , parseData: function (res) {
        return {
          "code": 0,
          "msg": res.msg,
          "count": res.count,
          "data": res.data
        };
      }
      , cellMinWidth: 100
      , cols: [[
        {field: 'id', title: 'ID', width: 60, align: 'center'}
        , {field: 'sort', title: '排序', width: 60, align: 'center'}
        , {field: 'cate_name', title: '所属分类', width: 130}
        , {field: 'thumb', title: '缩略图', width: 45, templet: '#thumbTpl', align: 'center'}
        , {field: 'title', title: '文章标题', minWidth: 200, templet: '#titleTpl'}
        , {field: 'flag', title: '属性', width: 145, templet: '#flagTpl'}
        , {field: 'click', title: '点击量', width: 80, align: 'center'}
        , {
          field: 'status', title: '状态', width: 80, align: 'center', templet: function (d) {
            if (d.status === 1) {
              return '<span class="layui-badge layui-bg-green">已发布</span>';
            } else {
              return '<span class="layui-badge layui-bg-orange">未发布</span>';
            }
          }
        }
        ,
        {field: 'update_time', title: '更新时间', width: 170, align: 'center'},
        {
          fixed: 'right', title: '操作', toolbar: '#barDemo', align: 'center', width: 130
        }
      ]]
      ,
      id: 'testReload'
      , page: true
      , limit: 15
    })
    ;
    var active = {
      reload: function () {
        //执行重载
        table.reload('testReload', {
          page: {curr: 1},
          where: {
            key: {
              title: $('#title').val(),
              id: $('#id').val(),
              cate_id: $('#cate_id').val(),
              flag: $('#attributes').val(),
              status: $('#status').val(),
            }
          }
        });
      }
    };
    $('.hui-form-search .layui-btn').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    $('.hui-form-search .reset').on('click', function () {
      window.location.reload();
    });

    //监听行工具事件
    table.on('toolbar(admin_table)', function (obj) {
      if (obj.event === 'refresh') {
        table.reload('testReload');
      }
    });

  });
</script>
</body>
</html>
